using Microsoft.AspNetCore.SignalR;

namespace Team.API.Hubs
{
    /// <summary>
    /// 设备状态SignalR Hub
    /// 用于实时推送设备状态更新
    /// </summary>
    public class EquipmentStatusHub : Hub
    {
        /// <summary>
        /// 客户端连接时触发
        /// </summary>
        public override async Task OnConnectedAsync()
        {
            await base.OnConnectedAsync();
            Console.WriteLine($"客户端已连接: {Context.ConnectionId}");
        }

        /// <summary>
        /// 客户端断开连接时触发
        /// </summary>
        public override async Task OnDisconnectedAsync(Exception? exception)
        {
            await base.OnDisconnectedAsync(exception);
            Console.WriteLine($"客户端已断开: {Context.ConnectionId}");
        }

        /// <summary>
        /// 向所有客户端推送设备状态更新消息
        /// </summary>
        public async Task SendEquipmentStatusUpdate(string message)
        {
            await Clients.All.SendAsync("ReceiveEquipmentStatusUpdate", message);
        }
    }
}
